//
//  YYChooseTeacherVC.m
//  drivingSchool
//
//  Created by 子yu 刘 on 2018/8/11.
//  Copyright © 2018年 子yu 刘. All rights reserved.
//

#import "YYChooseTeacherVC.h"
#import "YYChooseTeacherCell.h"

@interface YYChooseTeacherVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic ,assign) NSInteger selIndex;
@property (nonatomic ,copy)NSDictionary * teacher;

@end

@implementation YYChooseTeacherVC

- (void)viewDidLoad {
    [super viewDidLoad];
    _selIndex = -1;
    [self getData];
    
}
- (IBAction)corfirme:(id)sender {
    if (_block) {
        self.block(_teacher);
    }
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)getData{
    [RequestOperationManager teacherList_school_id:_schoolId success:^(id result) {
        if (DEF_REQ_SUCCESS) {
            self.dataArr = result[@"data"][@"list"];
            [self.tableView reloadData];
        }
        
    } failture:^(NSError *error) {
        
    }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    YYChooseTeacherCell * cell = [tableView dequeueReusableCellWithIdentifier:@"YYChooseTeacherCell"];
    NSDictionary * itme = self.dataArr[indexPath.row];
    cell.lbName.text = itme[@"teacher_name"];
    if (self.selIndex == indexPath.row) {
        [cell.selBtn setImage:DEF_IMAGENAME(@"sign_inspection vehicle_checkbox") forState:UIControlStateNormal];
    }else{
         [cell.selBtn setImage:DEF_IMAGENAME(@"sign_inspection vehicle_checkbox_anselected") forState:UIControlStateNormal];
    }
    MJWeakSelf;
    cell.block = ^{
        weakSelf.teacher = itme;
        weakSelf.selIndex = indexPath.row;
        [weakSelf.tableView reloadData];
    };
    return cell;
}

-(void)chooseTeacherBlock:(chooseTeacherBlock)block{
    _block = block;
}

@end
